<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$ 
 * 
 **************************************************************************/
 
 
 
/**
 * @file ValidationFloatTest.php
 * @author niulei(niulei@)
 * @date 2010/05/17 18:58:28
 * @version $Revision$ 
 * @brief 
 *  
 **/
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'validate/Validation.php';

class ValidationFloatTest extends PHPUnit_Framework_TestCase{

    protected function setUp()
    {			
       sleep(1);
    }
    
    public function testNoneChecked(){
    	$arr_rules = array(
    	                    'func' => 'FLOAT',
    	                    'flag' => array(
                                            'FLAG_ALLOW_THOUSAND',
                                           ),
                            //'min_range'=>0.99,//最小
                            //'max_range'=>100.99,//最大
                            //'decimal'=>3,
    	                   );
    	$input = "18.66";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "18.6";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "18";
    	$this->assertTrue(Validation::check($input,$arr_rules));
        $input = "18.666";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
    }

    public function testEmptyChecked(){
    	$input = "";
    	$arr_rules = array(
    	                    'func' => 'FLOAT',
    	                    'flag' => array(
                                            'FLAG_ALLOW_THOUSAND',
                                           ),
                            'min_range'=>1.99,//最小长度
                            'max_range'=>100.99,//最大长度
    	                   );
        $this->assertContains("Empty checked", Validation::check($input,$arr_rules));
        $arr_rules['flag'] = array(
                                    'FLAG_ALLOW_THOUSAND',
                                    'FLAG_ALLOW_EMPTY',
                                   );
        $this->assertTrue(Validation::check($input,$arr_rules));
    }
    
    public function testLengthChecked(){
    	$input = "180.33";
    	$arr_rules = array(
    	                    'func' => 'FLOAT',
    	                    'flag' => array(
                                            'FLAG_ALLOW_THOUSAND'
                                           ),
                            'min_range'=>0.99,
                            'max_range'=>100.99,
    	                   );
        
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
        $arr_rules['max_range'] = 200.99;
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "180.3";
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "180.33333";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $arr_rules['min_range'] = 190.99;
        $input = "180.3";
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));        
    }
    
    public function testThousandChecked(){
    	$input = "180.33";
    	$arr_rules = array(
    	                    'func' => 'FLOAT',
    	                    'flag' => array(
    	                                    'FLAG_ALLOW_THOUSAND',
                                           ),
                            'min_range'=>0.99,
                            'max_range'=>200000000.99,
    	                   );
        $this->assertTrue(Validation::check($input,$arr_rules));

        $input = "19,090,909.92";
        $this->assertTrue(Validation::check($input,$arr_rules));
 
        $input = "190,90,909.92";
        $this->assertContains("Thousand checked", Validation::check($input,$arr_rules));
    }
  
   public function testRegexpChecked(){
    	$input = "199.9999";
    	$arr_rules = array(
    	                    'func' => 'FLOAT',
    	                    'flag' => array(
    	                                    'FLAG_ALLOW_THOUSAND',
                                           ),
                            'min_range'=>0.99,
                            'max_range'=>200.99,
                            'decimal'=>3,
    	                   );
        
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = "199.999";
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "199.99";
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "199.";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = ".999";
        $this->assertContains("Regexp checked", Validation::check($input,$arr_rules));
        $input = "199.9";
        $this->assertTrue(Validation::check($input,$arr_rules));
    }
}
?>
